﻿using Max.PH4_2102A.Shopping.DTO;
using Max.PH4_2102A.Shopping.IService;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Max.PH4_2102A.Shopping.API.Controllers
{
    [Route("order/logistic")]
    [ApiController]
    public class OrderLogisticController : ControllerBase
    {
        IOrderMasterService _service;

        public OrderLogisticController(IOrderMasterService service)
        {
            _service = service;
        }

        /// <summary>
        /// 获取订单数据
        /// </summary>
        /// <param name="orderNo"></param>
        /// <param name="name"></param>
        /// <param name="state"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult Get(string? orderNo = "",string? name="",int state = -1,int pageIndex = 1,int pageSize = 10)
        {
            ResponseResultDto response = new();

            pageIndex = pageIndex <= 0 ? 1 : pageIndex;
            pageSize = pageSize <= 0 ? 10 : pageSize;
           
            var d = _service.GetOrderData(orderNo, name, state, pageIndex,pageSize, out int total);

            response.Data = new { items = d,total};

            return Ok(response);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="orderNo"></param>
        /// <returns></returns>
        [HttpGet("detail")]
        public IActionResult GetDetail(string orderNo)
        {
            ResponseResultDto response = new();

            //验证参数
            if(string.IsNullOrEmpty(orderNo))
            {
                response.Code = ResponseStateCode.Failed;
                response.Message = "参数无效";
                return Ok(response);
            }

            //获取服务层数据
            var d = _service.GetOrderDetailAndLogistic(orderNo);
            response.Data = d;

            return Ok(response);
        }


        /// <summary>
        /// 统计
        /// </summary>
        /// <returns></returns>
        [HttpGet("alysis")]
        public IActionResult GetOrderSaleAmount()
        {
            ResponseResultDto response = new();

            //获取服务层数据
            var d = _service.GetOrderSaleAmount();
            response.Data = d;

            return Ok(response);
        }


    }
}
